package com.chinatelecom.ctyun.xstore.vod.demo.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.chinatelecom.ctyun.xstore.vod.demo.config.VodConfig;
import com.ctyun.xstore.vod.template.TranscodeTemplateClient;
import com.ctyun.xstore.vod.template.WatermarkTemplateClient;
import com.ctyun.xstore.vod.transcode.TranscodeTaskClient;
import com.ctyun.xstore.vod.video.VideoClient;

@Component
public class XstoreVodClient {

	private volatile TranscodeTemplateClient transcodeTemplateClient = null;

	private volatile WatermarkTemplateClient watermarkTemplateClient = null;

	private volatile VideoClient videoClient = null;

	private volatile TranscodeTaskClient transcodeTaskClient = null;

	@Autowired
	private VodConfig vodConfig;

	public TranscodeTemplateClient getTranscodeTemplateClient() {
		if (transcodeTemplateClient == null) {
			synchronized (this) {
				if (transcodeTemplateClient == null) {
					transcodeTemplateClient = new TranscodeTemplateClient(vodConfig.getAccessKey(), vodConfig.getSecretKey());
				}
			}
		}
		return transcodeTemplateClient;
	}

	public WatermarkTemplateClient getWatermarkTemplateClient() {
		if (watermarkTemplateClient == null) {
			synchronized (this) {
				if (watermarkTemplateClient == null) {
					watermarkTemplateClient = new WatermarkTemplateClient(vodConfig.getAccessKey(), vodConfig.getSecretKey());
				}
			}
		}
		return watermarkTemplateClient;
	}

	public VideoClient getVideoClient() {
		if (videoClient == null) {
			synchronized (this) {
				if (videoClient == null) {
					videoClient = new VideoClient(vodConfig.getAccessKey(), vodConfig.getSecretKey());
				}
			}
		}
		return videoClient;
	}

	public TranscodeTaskClient getTranscodeTaskClient() {
		if (transcodeTaskClient == null) {
			synchronized (this) {
				if (transcodeTaskClient == null) {
					transcodeTaskClient = new TranscodeTaskClient(vodConfig.getAccessKey(), vodConfig.getSecretKey());
				}
			}
		}
		return transcodeTaskClient;
	}
}
